<?php
/***
* @version $Id: profile.php 336 2007-01-23 08:12:56Z flexiondotorg $
* @copyright (c) 2006 - 2007 Flexion.Org
*            (c) 2006              kkroo < princeomz2004@hotmail.com > (Omar Ramadan) http://phpbb-login.strangled.net
*            (c) 2006              Afterlife_69 < afterlife_69@hotmail.com > (Dean Newman) http://www.ugboards.com
*            (c) 2005 - 2006 {james} < james3785@gmail.com > (Laurence Herbert) http://www.vapour-online.com
*            (c) 2005 - 2006 Fountain of Apples < webmacster87@gmail.com > (Douglas Bell) http://www.webmacster87.info
*            (c) 2004 - 2005 Project Minerva
*            (c) 2001 - 2006 phpBB Group
* @license   http://opensource.org/licenses/gpl-license.php GNU Public License
***/

define('IN_R3BORN', true);
$root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'),	1);
include($root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_REGISTER);
init_userprefs($userdata);
//
// End session management
//

// session id check
$sid = get_var('sid', '');
$server_url = generate_website_url() . append_sid('register.' . $phpEx);

//
// Start of program proper
//
$mode = get_var('mode','');

if ( $mode == 'confirm' )
{
	// Visual Confirmation
	if ( $userdata['session_logged_in'] )
	{
		exit;
	}

	// Do we have an id? No, then just exit
	if (empty($_GET['id']))
	{
		exit;
	}

	$confirm_id = htmlspecialchars($_GET['id']);

	if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
	{
		$confirm_id = '';
	}

	// Try and grab code for this id and session
	$sql = 'SELECT code
			FROM ' . CONFIRM_TABLE . "
			WHERE session_id = '" . $userdata['session_id'] . "'
			AND confirm_id = '$confirm_id'";
	$result = $db->sql_query($sql);

	// If we have a row then grab data else create a new id
	if ($row = $db->sql_fetchrow($result))
	{
		$db->sql_freeresult($result);
		$code = $row['code'];
	}
	else
	{
		exit;
	}

	// Check if GD exisits, otherwise we will use the default confirm page ;)
	$gd = true;

	if(!extension_loaded('gd'))
	{
		//Gd isn't loaded
		//Display error messages always, or not?
		$gd = false;
	}

	if(!function_exists('gd_info') || !function_exists('imagettftext'))
	{
		//GD function, gd_info don't exists. GD isn't loaded correctly.
		//Freetype function imagettftext doesn't exists. This is required by this mod.
		//print "no gdinfo or imagettftext";
		$gd = false;
	}

	if($gd === false)
	{
		//GD not loaded, or one of the needed functions aren't available.
		include($root_path . 'includes/captcha/captcha_non_gd.' . $phpEx);
	}
	else
	{
		//GD is suitable for the advacned captcha
		include($root_path . 'includes/captcha/captcha_gd.' . $phpEx);
	}

	$captcha = new captcha();
	$captcha->execute($row['code']);
	exit;
}
elseif ( $mode == 'activate' )
{
	include($root_path . 'includes/usercp/usercp_activate.'.$phpEx);
	exit;
}
else if ( $mode == 'sendpassword' )
{
	include($root_path . 'includes/usercp/usercp_sendpasswd.'.$phpEx);
	exit;
}
else if ( $mode == 'resendactivation' )
{
	include ( $root_path . 'includes/usercp/usercp_sendactivation.'.$phpEx );
	exit;
}
else if ( $mode == 'sendusername' )
{
	include($root_path . 'includes/usercp/usercp_sendusername.'.$phpEx);
	exit;
}
elseif ($config['registrations_accept'])
{
	if ( !$userdata['session_logged_in'] )
	{
		include($root_path . 'includes/usercp/usercp_register.'.$phpEx);
		exit;
	}
}
elseif ( !$config['registrations_accept'] )
{
	$message .= $lang['Registrations_disabled'] . "<br /><br />" . sprintf($lang['Click_return_index'], "<a href=\"" . append_sid("index.".$phpEx) . "\">", "</a>");
	message_die(GENERAL_MESSAGE, $message);
}

redirect(append_sid('index.' . $phpEx, true));

?>